using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.Tilemaps;

namespace Game.Terrain.Terrain
{
    public class TerrainEntity
    {
        public int Position;
        public int ConfigId;
        public string Path;
        public TileBase BuildingTile;
        public BuildingUpgradeConfigItem ConfigItem;

        // 元素类型
        public string Type { get; private set; }

        // 元素名称
        public string Name { get; private set; }

        // 元素描述
        public string Description { get; private set; }
        
        // 行为集合
        private List<IElementBehavior> _behaviors = new List<IElementBehavior>();

        public void Init()
        {
            // 异步加载资源
            AsyncOperationHandle<TileBase> handle = Addressables.LoadAssetAsync<TileBase>(ConfigItem.IconPath);

            // 阻塞当前线程，直到加载完成
            handle.WaitForCompletion();

            if (handle.Status == AsyncOperationStatus.Succeeded)
            {
               BuildingTile = handle.Result;
            }
            else
            {
                Debug.LogError("Failed to load asset: " + ConfigItem.IconPath);
               
            }
        }

        // 添加行为
        public void AddBehavior(IElementBehavior behavior)
        {
            _behaviors.Add(behavior);
        }

        // 移除行为
        public void RemoveBehavior(IElementBehavior behavior)
        {
            _behaviors.Remove(behavior);
        }

        // 执行行为（根据策略选择）
        public void ExecuteBehaviors()
        {
           
        }
    }
}